# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=nanovg
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
pkgver=r416.f93799c
pkgrel=1
pkgdesc="Small antialiased vector graphics rendering library for OpenGL (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/memononen/nanovg"
license=('spdx:Zlib')
makedepends=("git" "${MINGW_PACKAGE_PREFIX}-premake4" "${MINGW_PACKAGE_PREFIX}-cc")
_commit="f93799c078fa11ed61c078c65a53914c8782c00b"
source=("${_realname}"::"git+https://github.com/memononen/nanovg.git#commit=${_commit}")
sha256sums=('7066b9214cda50291cb2dacea560981d7260b1e790099ce2191e9117b3d5762f')

case ${MINGW_CHOST} in
  i686*)
    _mach=x86
    _ctype=release32
  ;;
  x86_64*)
    _mach=x86_64
    _ctype=release64
  ;;
  aarch64*)
    _mach=aarch64
    _ctype=release64
  ;;
esac

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

build() {
  cd "${srcdir}"
  rm -rf "${MSYSTEM}" || true
  cp -rf "${srcdir}/${_realname}" "${srcdir}/${MSYSTEM}"
  cd "${srcdir}/${MSYSTEM}"
  premake4 gmake --os=windows cc=cc
  cd build
  make config=${_ctype} nanovg
}

package() {
  install -v -Dm644 "${srcdir}/$MSYSTEM/build/libnanovg.a" "${pkgdir}${MINGW_PREFIX}/lib/libnanovg.a" || exit 1
  install -v -Dm644 "${srcdir}/$MSYSTEM/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/LICENSE.txt" || exit 1
  install -v -Dm644 "${srcdir}/$MSYSTEM/src/nanovg.h" "${pkgdir}${MINGW_PREFIX}/include/nanovg/nanovg.h" || exit 1
  install -v -Dm644 "${srcdir}/$MSYSTEM/src/nanovg_gl.h" "${pkgdir}${MINGW_PREFIX}/include/nanovg/nanovg_gl.h" || exit 1
  install -v -Dm644 "${srcdir}/$MSYSTEM/src/nanovg_gl_utils.h" "${pkgdir}${MINGW_PREFIX}/include/nanovg/nanovg_gl_utils.h" || exit 1
  install -v -Dm644 "${srcdir}/$MSYSTEM/src/fontstash.h" "${pkgdir}${MINGW_PREFIX}/include/nanovg/fontstash.h" || exit 1
}
